//
//  LHQDestinationHotTableViewCell.m
//  God_is_a_Girl
//
//  Created by dllo on 15/9/26.
//  Copyright (c) 2015年 呸. All rights reserved.
//

#import "LHQDestinationHotTableViewCell.h"
#import "LHQDestinationHotDetailCollectionViewCell.h"
#import <AFNetworking.h>
#import <UIImageView+WebCache.h>
@interface LHQDestinationHotTableViewCell() <UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, retain) NSMutableArray *Marr;
@property (nonatomic, retain) UICollectionViewFlowLayout *flowLayout;
@end

@implementation LHQDestinationHotTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        self.flowLayout = [[UICollectionViewFlowLayout alloc]init];
        self.flowLayout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - 30) / 2, ([UIScreen mainScreen].bounds.size.width - 30) / 2);
        self.flowLayout.minimumInteritemSpacing = 10;
        self.flowLayout.minimumLineSpacing = 10;
        self.flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        self.hotspotCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, (20 / 2 + 20 % 2) * (([UIScreen mainScreen].bounds.size.width - 30) / 2 + 10) + 10) collectionViewLayout:self.flowLayout];
        
        self.hotspotCollectionView.backgroundColor = [UIColor whiteColor];
        self.hotspotCollectionView.dataSource = self;
        self.hotspotCollectionView.delegate = self;
        [self.contentView addSubview:self.hotspotCollectionView];
        
        [self.hotspotCollectionView registerClass:[LHQDestinationHotDetailCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
        
       
    
    
    }
    
    return self;
}

- (void)layoutSubviews
{
    
    [super layoutSubviews];
    [self dataHandle];
}

#pragma mark - 数据处理

- (void)dataHandle
{
    /* 和上面一样 */
    
    self.Marr = [NSMutableArray  array];
    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
    NSString *urlStr = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%ld/%@/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.88252056120492&longitude=121.53961915009307", (long)self.Type, self.ID];
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.Marr = [responseObject objectForKey:@"items"];
        [self.hotspotCollectionView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}
#pragma mark - collection
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.Marr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LHQDestinationHotDetailCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    
    [cell.hotspotImageView sd_setImageWithURL:[NSURL URLWithString:[[self.Marr objectAtIndex:indexPath.item]objectForKey:@"cover_s" ]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]] ;
    cell.hotSpotName.text = [[self.Marr objectAtIndex:indexPath.item]objectForKey:@"name" ];
   
    return cell;
}




















- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
